package com.thirteengroup.casemg.controller;


import com.thirteengroup.casemg.domain.JasonResult;
import com.thirteengroup.casemg.domain.PageResult;
import com.thirteengroup.casemg.domain.queryObject;
import com.thirteengroup.casemg.domain.trans;
import com.thirteengroup.casemg.service.ICustomerService;
import com.thirteengroup.casemg.service.impl.TransService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/trans")
public class transController {


    @Resource
    ICustomerService customerService;

    final TransService transService;
    @Autowired
    public transController(TransService transService) {
        this.transService = transService;
    }

    @GetMapping("list")
    @ResponseBody
    public JasonResult queryAll(queryObject queryObject){
        Integer totalCount=transService.queryCount();
        List<trans> trans = transService.queryAll(queryObject);
        PageResult<trans> pageResult=new PageResult<>(queryObject.getCurrentPage(),totalCount, queryObject.getPageSize(), trans);
        JasonResult jasonResult=new JasonResult("查询成功",true,pageResult);
        return  jasonResult;
    }

    @PostMapping("insert")
    @ResponseBody
    public JasonResult insert(trans t){
        Long customerid=t.getCu().getId();
        Long newSellerid=t.getNewSeller().getId();
        customerService.updateInputUser(newSellerid,(Long)customerid);
        transService.insert(t);
        return new JasonResult("插入成功",true,null);
    }

    @PostMapping("delete")
    @ResponseBody
    public JasonResult delete(Long id){
        transService.delete(id);
        return new JasonResult("删除成功",true,null);
    }




}
